package com.shujia.flink.tf;

import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class Demo3Filter {
    public static void main(String[] args) throws Exception {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<String> studentDS = env.readTextFile("flink/data/students.csv");

        //匿名内部类
        DataStream<String> filterDS = studentDS
                .filter(new FilterFunction<String>() {
                    @Override
                    public boolean filter(String value) throws Exception {
                        String clazz = value.split(",")[4];
                        return "文科一班".equals(clazz);
                    }
                });

        //filterDS.print();

        //lambda表达式
        studentDS.filter(value -> {
            String clazz = value.split(",")[4];
            return "文科一班".equals(clazz);
        }).print();

        env.execute();
    }
}
